package com.example.controller;


import com.example.entity.Script;
import com.example.entity.Storyboardfiles;
import com.example.result.Result;
import com.example.service.IStoryboardfilesService;
import lombok.Data;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.web.multipart.MultipartFile;

import lombok.extern.slf4j.Slf4j;
import java.io.IOException;
import java.util.List;


/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 陈昌吉
 * @since 2024-04-16
 */
@RestController
@Slf4j
@CrossOrigin
@Data
@RequestMapping("/storyboardfiles")
public class StoryboardfilesController {

    @Autowired
    private IStoryboardfilesService storyboardfilesService;

    /*
    * Storyboardfiles上传文件
    * */
    @PostMapping("/file")
    public Result<List<Storyboardfiles>> transferFile(MultipartFile file, @RequestParam Integer hid) throws IOException{
        List<Storyboardfiles> insert=storyboardfilesService.insert(file,hid);
        return Result.success(insert);
    }

    /**
    * 根据hid(作业id)和login_id(学生id)获取所有Storyboardfiles
    */
    @PostMapping("/getAllStory")
    public Result<List<Storyboardfiles>> getAllStory(@RequestBody Integer hid){
        log.info("额外{},",hid);
        List<Storyboardfiles>  all= storyboardfilesService.getAll(hid);
        return Result.success(all);
    }

    /**
     * 删除Storyboardfiles中的url
     */
    @DeleteMapping("/deleteUrl")
    public Result removeFile(@RequestBody Storyboardfiles storyboardfiles){
        log.info("文件为,{}",storyboardfiles);
        String s = storyboardfilesService.deleteFile(storyboardfiles);
        return Result.success(s);
    }

    //审核员处

    /**
     * 审核员处获取所有的作业
     */
    @PostMapping("/getStory")
    public Result<List<Storyboardfiles>> getStory(@RequestBody Storyboardfiles storyboardfiles){
        log.info("审核员处{},",storyboardfiles);
        List<Storyboardfiles> story= storyboardfilesService.getStory(storyboardfiles);
        return Result.success(story);
    }

    /**
     * 审核对提交的作业进行审核
     */
    @PostMapping("updateState")
    public Result  updatesState(@RequestBody Storyboardfiles storyboardfiles){
        log.info("审核后的状态为:{},",storyboardfiles);
        storyboardfilesService.updateState(storyboardfiles);
        return Result.success();
    }

}
